package com.example.bgmachine.bgmachine.homes;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

public class CupView extends View {
    private Paint paint;

    public CupView(Context context) {
        super(context);
        init();
    }

    public CupView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CupView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setColor(0xFF000000); // 黑色
        paint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(Color.BLACK); // 设置线条颜色
        paint.setStyle(Paint.Style.STROKE); // 设置为描边模式
        paint.setStrokeWidth(1f); // 设置线条宽度
        paint.setAntiAlias(true);
        RectF rect;
        rect = new RectF(0, 0, getWidth(), 10);
        // 绘制纸杯的主体
       // canvas.drawCircle(getWidth() / 2, getHeight() / 2, Math.min(getWidth(), getHeight()) / 2, paint);

        // 绘制杯口
        //canvas.drawCircle(getWidth() / 2, getHeight() / 4, Math.min(getWidth(), getHeight()) / 8, paint);
        canvas.drawOval(rect, paint);
        canvas.drawLine(0, 5,4, getHeight(), paint);
        canvas.drawLine(4, getHeight(),getWidth() -4, getHeight(), paint);

        canvas.drawLine(getWidth()-4, getHeight(),getWidth() , 5, paint);
    }
}
